import ecfsConfig from '../../../config/ecfs.config.js'
import * as partyApi from '../../../api/party.js'
/**
 * 保存当事人，向后台发请求
 */
export function handleSaveAgent(page) {
  var that = page
  const config = {
    url: ecfsConfig.IS_PRODUCTION ? (ecfsConfig.SERVER_DOMAIN + ecfsConfig.SAVE_AGENT_URL) : (ecfsConfig.SERVER_DOMAIN + ecfsConfig.RAP_URL_PREFIX + ecfsConfig.SAVE_AGENT_URL),
    data: that.data.saveAgent,
  }
  console.log(that.data.saveAgent)
  partyApi.saveAgent(config).then(res => {
    if (res.data.code === 200) {
      that.setData({
        savedAgent: res.data.body
      });
      //保存成功返回之前界面，并将原告信息保存
      wx.showToast({
        title: '保存成功',
        icon: 'success',
        duration: 1000
      })
    } else {
      console.log(res)
    }
  }).catch(error => {
    console.log(error)
  })
}
/**
 * 删除当事人向后台发请求
 */
export function handleDeleteAgent(page, content) {
  var that = page
  const config = {
    url: ecfsConfig.IS_PRODUCTION ? (ecfsConfig.SERVER_DOMAIN + ecfsConfig.DELETE_AGENT_URL) : (ecfsConfig.SERVER_DOMAIN + ecfsConfig.RAP_URL_PREFIX + ecfsConfig.DELETE_AGENT_URL),
    data: that.data.saveAgent,
  }
  partyApi.deleteAgent(config).then(res => {
    if (res.data.code === 200) {
      //删除成功返回之前界面，并将原告信息删除
      wx.showToast({
        title: '删除成功',
        icon: 'success',
        duration: 1000
      })
    } else {
      console.log(data.code)
    }
  }).catch(error => {
    console.log(error)
  })
}